/**
 * 
 * 广州锐鹏计算机科技有限公司（www.ruipengkj.com）
 * 
 * 
 * Copyright (c) 2011-2012 RUIPENGKJ.Co.Ltd. All rights reserved.
 * 
 * */
package com.ruipengkj.view.base;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JInternalFrame;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.event.InternalFrameEvent;
import javax.swing.event.InternalFrameListener;
import javax.swing.plaf.basic.BasicInternalFrameUI;

import com.ruipengkj.ApplicationConfig;
/**
 * 说明：
 * InternalFrame基类
 * @Author：李智深
 * @Date：2012-03-15
 */
public class BaseInternalFrame extends JInternalFrame implements ActionListener,InternalFrameListener{

	
	private static final long serialVersionUID = 1L;

	private boolean isShowing=false;
	private boolean isHidden = false; 
	private BasicInternalFrameUI oldUi = null; 
	private JPanel opPane;
	public BaseInternalFrame(String title, boolean resizable, boolean closable, boolean maximizable,boolean iconifiable){
		super(title, resizable, closable, maximizable,iconifiable);
		this.setSize(ApplicationConfig.APP_WIDTH-5, ApplicationConfig.APP_HEIGHT-160);
		this.addInternalFrameListener(this);
//		this.addComponentListener(this);
		this.setBorder(null);
		this.setFrameIcon(ApplicationConfig.APP_ICOM);
		oldUi = (BasicInternalFrameUI) getUI();
		
		maximizable = true;
		closable = true;
//		this.hideNorthPanel();
	}
	
    /** 
     * Hide north panel. 
     */ 
    public void hideNorthPanel(){ 
        ((BasicInternalFrameUI) this.getUI()).setNorthPane(null); 
        this.putClientProperty("JInternalFrame.isPalette", Boolean.TRUE); 
        isHidden = true; 
    } 
 
    /** 
     * Show north panel. 
     */ 
    public void showNorthPanel() { 
        this.setUI(oldUi); 
        this.putClientProperty("JInternalFrame.isPalette", Boolean.FALSE); 
        isHidden = false; 
    } 
 
    /* (non-Javadoc) 
     * @see javax.swing.JInternalFrame#updateUI() 
     */ 
    public void updateUI() { 
        super.updateUI(); 
//        if (isHidden) { 
//            hideNorthPanel(); 
//        } 
     } 
	

	public JPanel getOpPane() {
		return opPane;
	}


	public void setOpPane(JPanel opPane) {
		this.opPane = opPane;
	}


	public boolean isShowing() {
		return isShowing;
	}


	@Override
	public void actionPerformed(ActionEvent e) {
		
	}
	
	public void showing(){
		isShowing=true;
		this.setVisible(true);
	}

	@Override
	public void internalFrameActivated(InternalFrameEvent e) {
	}



	@Override
	public void internalFrameClosed(InternalFrameEvent e) {
		isShowing=false;
	}



	@Override
	public void internalFrameClosing(InternalFrameEvent e) {
		isShowing=false;
	}



	@Override
	public void internalFrameDeactivated(InternalFrameEvent e) {
		
	}



	@Override
	public void internalFrameDeiconified(InternalFrameEvent e) {
		
	}



	@Override
	public void internalFrameIconified(InternalFrameEvent e) {
		// TODO Auto-generated method stub
		
	}



	@Override
	public void internalFrameOpened(InternalFrameEvent e) {
		// TODO Auto-generated method stub
		
	}
	
	@Override
	public void doDefaultCloseAction() {
		// 关闭的提示选择
		int result = JOptionPane.showConfirmDialog(this,"是否要退出吗？", "关闭", JOptionPane.YES_NO_OPTION);
		if (result == JOptionPane.YES_OPTION) {
			// 如果选择YES，交由上层设置的关闭处理
			super.doDefaultCloseAction();
		}
	}


//	@Override
//	public void componentHidden(ComponentEvent arg0) {
//		// TODO Auto-generated method stub
//		
//	}
//
//
//	@Override
//	public void componentMoved(ComponentEvent arg0) {
//		
//		
//	}
//
//
//	@Override
//	public void componentResized(ComponentEvent e) {
//		BaseInternalFrame selectedFrame = (BaseInternalFrame) e.getSource();
//		if (selectedFrame.isMaximum()) {
//			selectedFrame.hideNorthPanel();
//			this.setBorder(null);
//			opPane.setVisible(true);
//			try {
//				selectedFrame.setMaximum(true);
//			} catch (PropertyVetoException ex) {
//				ex.printStackTrace();
//			}
//		}
//	}
//
//
//	@Override
//	public void componentShown(ComponentEvent arg0) {
//		// TODO Auto-generated method stub
//		
//	}
}
